package com.cloudptt.wp.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.cloudptt.api.product.Product;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.SysApplication;
import com.cloudptt.wp.ui.views.listener.CallSysDlgListener;
import com.mcptt.db.model.AddrInfo;

/**
 * on 2017/7/19.
 * 类的描述:
 */

public class SessionMenuLayout extends FrameLayout implements View.OnClickListener {
	private Context context = null;
	private LinearLayout funcPic = null;
	private LinearLayout funcCamera = null;
	private LinearLayout funcFile = null;
	private LinearLayout funcLocal = null;

	private LinearLayout funcVoice = null;
	private LinearLayout funcVideo = null;
	private LinearLayout funcVideoPush = null;
	private LinearLayout funcVideoPull = null;
	private LinearLayout llVideo = null;
	private LinearLayout llBusinessCard = null;

	private AddrInfo addrInfo = null;
	private CallSysDlgListener listener = null;

	public SessionMenuLayout(Context context) {
		this(context, null);
		this.context = context;
	}

	public SessionMenuLayout(Context context, AttributeSet attrs) {
		//这里构造方法也很重要，不加这个很多属性不能再XML里面定义
		this(context, attrs, 0);
		this.context = context;
	}

	public SessionMenuLayout(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		this.context = context;
		init(context);
	}

	public SessionMenuLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
		super(context, attrs, defStyleAttr, defStyleRes);
		this.context = context;
		init(context);
	}
	private void init(Context context)
	{
		LayoutInflater.from(context).inflate(R.layout.fragment_func_page1, this);
		funcPic = (LinearLayout)findViewById(R.id.funcPic);
		funcPic.setOnClickListener(this);
		funcCamera = (LinearLayout)findViewById(R.id.funcCamera);
		funcCamera.setOnClickListener(this);
		funcFile = (LinearLayout)findViewById(R.id.funcFile);
		funcFile.setOnClickListener(this);
		funcLocal = (LinearLayout)findViewById(R.id.funcLocal);
		funcLocal.setOnClickListener(this);

		funcVoice = (LinearLayout)findViewById(R.id.funcVoice);
		funcVoice.setOnClickListener(this);

		funcVideo = (LinearLayout)findViewById(R.id.funcVideo);
		funcVideo.setOnClickListener(this);

		funcVideoPush = (LinearLayout)findViewById(R.id.funcVideoPush);
		funcVideoPush.setOnClickListener(this);

		funcVideoPull = (LinearLayout)findViewById(R.id.funcVideoPull);
		funcVideoPull.setOnClickListener(this);
		/*llVideo = (LinearLayout)findViewById(R.id.llVideo);
		llVideo.setOnClickListener(this);
		llBusinessCard = (LinearLayout)findViewById(R.id.llBusinessCard);
		llBusinessCard.setOnClickListener(this);*/
	}

	public void setListener(AddrInfo addrInfo, CallSysDlgListener listener) {
		this.addrInfo = addrInfo;
		if(addrInfo.isGroupType())
		{
			funcVoice.setVisibility(View.INVISIBLE);
//			funcVideo.setVisibility(View.GONE);
			funcVideoPush.setVisibility(View.INVISIBLE);
			funcVideoPull.setVisibility(View.INVISIBLE);
		}
		this.listener = listener;
	}


	@Override
	public void onClick(View v) {
		SysApplication app = ((SysApplication) context.getApplicationContext());
		Product product = app.getProduct();
		if(listener == null)
		{
			return;
		}
		switch (v.getId()) {

			case R.id.funcPic:
				Log.debug(this.getClass(),"onClick funcPic");
				listener.onCallSysDlg(CallSysDlgListener.CHOOSE_PIC);
				break;

			case R.id.funcCamera:
				Log.debug(this.getClass(),"onClick funcCamera");
				listener.onCallSysDlg(CallSysDlgListener.OPEN_CAMERA);
				break;

			case R.id.funcFile:
				Log.debug(this.getClass(),"onClick funcFile");
				listener.onCallSysDlg(CallSysDlgListener.CHOOSE_FILE);
				break;
			default:
				Log.debug(this.getClass(),"onDoFun v.getId() = " + v.getId());
				listener.onDoFun(v.getId());
				break;
		}
	}
}
